package com.dkd.manage.service.Impl;

import com.dkd.common.utils.SecurityUtils;
import com.dkd.manage.mapper.ChannelMapper;
import com.dkd.manage.pojo.dto.ChannelDto;
import com.dkd.manage.pojo.entity.Channel;
import com.dkd.manage.pojo.vo.ChannelVo;
import com.dkd.manage.service.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class ChannelServiceImpl implements ChannelService {


    @Autowired
    private ChannelMapper channelMapper;

    /**
     * 查询货道列表
     * @param innerCode
     * @return
     */
    @Override
    public List<ChannelVo> list(String innerCode) {
        //根据设备编号查询货道列表
        return channelMapper.list(innerCode);
    }


    /**
     * 新增货道
     * @param channel
     * @return
     */
    @Override
    public Integer add(Channel channel) {
        return channelMapper.add(channel);
    }

    /**
     * 根据id查询货道
     * @param id
     * @return
     */
    @Override
    public Channel getChannelById(Long id) {
        return channelMapper.getChannelById(id);
    }

    /**
     * 修改设备类型
     * @param channel
     * @return
     */
    @Override
    public Integer edit(Channel channel) {
        return channelMapper.edit(channel);
    }

    /**
     * 根据id删除货道
     * @param ids
     * @return
     */
    @Override
    public Integer deleteChannelById(Long[] ids) {

        return channelMapper.deleteChannelById(ids);
    }

    /**
     * 修改设备的货道
     * @param channelDto
     * @return
     */
    @Override
    public Integer config(ChannelDto channelDto) {
        //取出要修改的货道列表
        List<Channel> channelList = channelDto.getChannelList();
        channelList.forEach(channel -> {
            channel.setUpdateTime(LocalDateTime.now());
            channel.setUpdateBy(SecurityUtils.getUsername());
        });
        //根据设备编号和货道编号批量修改货道列表
        return channelMapper.updateBatch(channelList);
    }
}
